; REQUIRES: x86-registered-target

; Incorrect function matching during comparison.
; https://github.com/llvm/llvm-project/issues/57040

; Output generated by g++ (Debian 11.3.0-3) 11.3.0

; .debug_info contents:
; format = DWARF32, version = 0x0005, unit_type = DW_UT_compile
;
; DW_TAG_compile_unit
;   DW_TAG_subprogram ("foo")
;     DW_AT_decl_file	(1)
;
;     DW_TAG_formal_parameter ("ParamPtr")
;       DW_AT_decl_file	(1)
;
; .debug_line contents:
; Line table prologue:
;           format: DWARF32, version: 5
; include_directories[0] = "/usr/local/google/home/aheejin/test/llvm-dva"
; file_names[0]: name: "test.cpp" dir_index: 0
; file_names[1]: name: "test.cpp" dir_index: 0

; The values for DW_AT_decl_file are 1-indexed.

; test.cpp
;  1  using INTPTR = const int *;
;  2  int foo(INTPTR ParamPtr, unsigned ParamUnsigned, bool ParamBool) {
;  3    if (ParamBool) {
;  4      typedef int INTEGER;
;  5      const INTEGER CONSTANT = 7;
;  6      return CONSTANT;
;  7    }
;  8    return ParamUnsigned;
;  9  }

; RUN: llvm-debuginfo-analyzer --attribute=level,producer \
; RUN:                         --compare=types \
; RUN:                         --report=view \
; RUN:                         --print=symbols,types \
; RUN:                         %p/Inputs/pr-57040-test-dwarf-clang.o \
; RUN:                         %p/Inputs/pr-57040-test-dwarf-gcc.o 2>&1 | \
; RUN: FileCheck --strict-whitespace -check-prefix=ONE %s

; ONE:      Reference: 'pr-57040-test-dwarf-clang.o'
; ONE-NEXT: Target:    'pr-57040-test-dwarf-gcc.o'
; ONE-EMPTY:
; ONE-NEXT: Logical View:
; ONE-NEXT:  [000]           {File} 'pr-57040-test-dwarf-clang.o'
; ONE-EMPTY:
; ONE-NEXT:  [001]             {CompileUnit} 'test.cpp'
; ONE-NEXT:  [002]               {Producer} 'clang version 14.0.6'
; ONE-NEXT:  [002]     1         {TypeAlias} 'INTPTR' -> '* const int'
; ONE-NEXT:  [002]     2         {Function} extern not_inlined 'foo' -> 'int'
; ONE-NEXT:  [003]                 {Block}
; ONE-NEXT:  [004]     5             {Variable} 'CONSTANT' -> 'const INTEGER'
; ONE-NEXT: +[004]     4             {TypeAlias} 'INTEGER' -> 'int'
; ONE-NEXT:  [003]     2           {Parameter} 'ParamBool' -> 'bool'
; ONE-NEXT:  [003]     2           {Parameter} 'ParamPtr' -> 'INTPTR'
; ONE-NEXT:  [003]     2           {Parameter} 'ParamUnsigned' -> 'unsigned int'
; ONE-NEXT: -[003]     4           {TypeAlias} 'INTEGER' -> 'int'

; RUN: llvm-debuginfo-analyzer --attribute=level \
; RUN:                         --compare=types \
; RUN:                         --report=list \
; RUN:                         --print=symbols,types,summary \
; RUN:                         %p/Inputs/pr-57040-test-dwarf-clang.o \
; RUN:                         %p/Inputs/pr-57040-test-dwarf-gcc.o 2>&1 | \
; RUN: FileCheck --strict-whitespace -check-prefix=TWO %s

; TWO:      Reference: 'pr-57040-test-dwarf-clang.o'
; TWO-NEXT: Target:    'pr-57040-test-dwarf-gcc.o'
; TWO-EMPTY:
; TWO-NEXT: (1) Missing Types:
; TWO-NEXT: -[003]     4     {TypeAlias} 'INTEGER' -> 'int'
; TWO-EMPTY:
; TWO-NEXT: (1) Added Types:
; TWO-NEXT: +[004]     4     {TypeAlias} 'INTEGER' -> 'int'
; TWO-EMPTY:
; TWO-NEXT: ----------------------------------------
; TWO-NEXT: Element   Expected    Missing      Added
; TWO-NEXT: ----------------------------------------
; TWO-NEXT: Scopes           4          0          0
; TWO-NEXT: Symbols          0          0          0
; TWO-NEXT: Types            2          1          1
; TWO-NEXT: Lines            0          0          0
; TWO-NEXT: ----------------------------------------
; TWO-NEXT: Total            6          1          1

; Changing the 'Reference' and 'Target' order:

; RUN: llvm-debuginfo-analyzer --attribute=level,producer \
; RUN:                         --compare=types \
; RUN:                         --report=view \
; RUN:                         --print=symbols,types \
; RUN:                         %p/Inputs/pr-57040-test-dwarf-gcc.o \
; RUN:                         %p/Inputs/pr-57040-test-dwarf-clang.o 2>&1 | \
; RUN: FileCheck --strict-whitespace -check-prefix=THR %s

; THR:      Reference: 'pr-57040-test-dwarf-gcc.o'
; THR-NEXT: Target:    'pr-57040-test-dwarf-clang.o'
; THR-EMPTY:
; THR-NEXT: Logical View:
; THR-NEXT:  [000]           {File} 'pr-57040-test-dwarf-gcc.o'
; THR-EMPTY:
; THR-NEXT:  [001]             {CompileUnit} 'test.cpp'
; THR-NEXT:  [002]               {Producer} 'GNU C++17 11.3.0 {{.*}}'
; THR-NEXT:  [002]     1         {TypeAlias} 'INTPTR' -> '* const int'
; THR-NEXT:  [002]     2         {Function} extern not_inlined 'foo' -> 'int'
; THR-NEXT:  [003]                 {Block}
; THR-NEXT: -[004]     4             {TypeAlias} 'INTEGER' -> 'int'
; THR-NEXT:  [004]     5             {Variable} 'CONSTANT' -> 'const INTEGER'
; THR-NEXT:  [003]     2           {Parameter} 'ParamBool' -> 'bool'
; THR-NEXT:  [003]     2           {Parameter} 'ParamPtr' -> 'INTPTR'
; THR-NEXT:  [003]     2           {Parameter} 'ParamUnsigned' -> 'unsigned int'
; THR-NEXT: +[003]     4           {TypeAlias} 'INTEGER' -> 'int'

; RUN: llvm-debuginfo-analyzer --attribute=level \
; RUN:                         --compare=types \
; RUN:                         --report=list \
; RUN:                         --print=symbols,types,summary \
; RUN:                         %p/Inputs/pr-57040-test-dwarf-gcc.o \
; RUN:                         %p/Inputs/pr-57040-test-dwarf-clang.o 2>&1 | \
; RUN: FileCheck --strict-whitespace -check-prefix=FOU %s

; FOU:      Reference: 'pr-57040-test-dwarf-gcc.o'
; FOU-NEXT: Target:    'pr-57040-test-dwarf-clang.o'
; FOU-EMPTY:
; FOU-NEXT: (1) Missing Types:
; FOU-NEXT: -[004]     4     {TypeAlias} 'INTEGER' -> 'int'
; FOU-EMPTY:
; FOU-NEXT: (1) Added Types:
; FOU-NEXT: +[003]     4     {TypeAlias} 'INTEGER' -> 'int'
; FOU-EMPTY:
; FOU-NEXT: ----------------------------------------
; FOU-NEXT: Element   Expected    Missing      Added
; FOU-NEXT: ----------------------------------------
; FOU-NEXT: Scopes           4          0          0
; FOU-NEXT: Symbols          0          0          0
; FOU-NEXT: Types            2          1          1
; FOU-NEXT: Lines            0          0          0
; FOU-NEXT: ----------------------------------------
; FOU-NEXT: Total            6          1          1
